/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.td;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.FPSLogger;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import org.td.engine.GameScene;
import org.td.engine.Player;

/**
 *
 * @author Администратор
 */
public class Application extends Game {

    private static Application instance;
    
    private AssetManager assetManager;
    private GameScene gameScene;

    
    FPSLogger logger = new FPSLogger();



    @Override
    public void create() {

        Gdx.graphics.setVSync(false);
        instance = this;
        assetManager = new AssetManager();
        loadResources();
        
        gameScene = new GameScene(new Player());
        setScreen(gameScene);
    }
    
    private void loadResources() {
        assetManager.load("assets/assets.atlas", TextureAtlas.class);
        assetManager.finishLoading();
    }

    public static TextureRegion findAsset(String assetFile) {
        if (instance != null) {
            TextureAtlas atlas = instance.assetManager.get("assets/assets.atlas", TextureAtlas.class);
            return atlas.findRegion(assetFile);
        } else {
            throw new IllegalStateException("Application isn't initialized!");
        }
    }
    
    public static AssetManager getAssetManager() {
        if (instance != null) {
            return instance.assetManager;
        } else {
            throw new IllegalStateException("Application isn't initialized!");
        }
    }


    
    
}
